package com.thlws.consul.gateway.config;

import com.thlws.consul.gateway.filter.MyFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author HanleyTang 2019-06-19
 */
@Configuration
public class RouteConfig {

    @Autowired
    private MyFilter myFilter;

    @Bean
    public RouteLocator customerRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route(r -> r.path("/mypath/**")
                        //若MyFilter 不受容器管理，这里可以直接 new MyFilter()
                        .filters(f -> f.filter(myFilter)
                        .addResponseHeader("X-Response-Default-Foo", "Default-Bar"))
                        .uri("http://www.qq.com")
                        .order(0)
                        .id("my_filter_router")
                )
                .build();
    }

}
